﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QLabel>
#include <QMainWindow>
#include <QMessageBox>
#include <QTableWidget>
#include <QTimer>
#include <vector>
#include <QStatusBar>
#include <QtMath>
#include <QSettings>
#include <QFile>
#include <QFileDialog>
#include <QDateTime>
#include <QDesktopServices>
#include <QThread>


#include "modbusrtu.h"
#include "SaveThread.h"

#define m_DateTime QDateTime::currentDateTime().toString("yyMMdd hh_mm_ss")
#define m_Time QDateTime::currentDateTime().toString("hh:mm:ss")

typedef union _TwoByte{
    unsigned char uc2[2];
    char c2[2];
    unsigned short us;
    short s;
}TwoByte;

namespace Ui {
class MainWindow;
}

/* 两种温度模式 */
#define Decimal 0
#define NoDecimal 1

/* 定义模式 */
//#define RobootAlarm //机器报警


class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
public slots:
    virtual void closeEvent(QCloseEvent *);
signals:
    void SaveExcel(QTableWidget *tablewidget, const QString &filename);
    void SaveTxt(QListWidget *lw, QString filename);
private slots:
    void NowTime();
    void on_ControlPortCB_clicked();
    void answer();
    void on_ClearMessagePB_clicked();

private:
    void Init_UIPort();
    void Init_Setini();
    void Init_Thread();
    void UIState(bool state);
    void SerialPortClose();
    bool SerialPortOpen();
private:
    Ui::MainWindow *ui;
    QSerialPort *MySerialPort = nullptr;
    bool portStatus = false;
    ModbusRTU *modbus = nullptr;
    QTimer *time = nullptr;
    QLabel nowtime;
};

#endif // MAINWINDOW_H
